﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuildPlannerLib.SimEvents;

namespace BuildPlannerLib.PlayerActions
{
    // Derived class of Action for moving gas workers to minerals
    public class GasToMineral : PlayerAction
    {
        // Field for the base where the worker is being moved to minerals
        public Base Base;

        // Constructor with parameters for base and build
        public GasToMineral(Build build, Base b)
        {
            Build = build;
            Base = b;
            Description = "Worker to Minerals (Base " + Build.Map.Bases.IndexOf(Base) + ")";
            LongDescription = "Moving a worker from Gas to Minerals at base number " + Build.Map.Bases.IndexOf(Base) + ".";
        }

        // Evaluates whether there are workers mining gas at the base
        public override bool RequirementsFilled()
        {
            Error = null;

            if (Base.GasWorkers == 0)
            {
                Error = "No workers assigned to gas at the specified base.";
                return false;
            }

            return base.RequirementsFilled();
        }

        // Evaluates if there is a gas worker in the Leaving or Idle categories
        public override bool StartCheck()
        {
            if (Base.GasWorkerStatus.Sum() == 0)
                return false;

            return base.StartCheck();
        }

        // Removes the worker from gas and adds the worker to minerals
        public override void StartAction()
        {
            base.StartAction();

            Base.RemoveGasWorker(ref Build);
            Base.AddMineralWorker(ref Build);
        }
    }
}
